@extends('layouts.layout')

@section('title', '角色列表')

@section('CONTENT')
    <div class="box">
        <div class="box-body">
        </div>
    </div>
    <div class="box">
        <div class="box-header with-border">
            <h3 class="box-title">角色列表</h3>
            <div class="box-tools">
                <a href="{{ route('role.create') }}" class="btn btn-default btn-sm">添加角色</a>
            </div>
        </div>
        <!-- /.box-header -->
        <div class="box-body">
            @if( isset($roles) )
                <table class="table table-bordered">
                    <tr>
                        <th>角色标识</th>
                        <th>角色名</th>
                        <th>创建时间</th>
                        <th style="width: 200px">操作</th>
                    </tr>
                    @foreach($roles as $role)
                        <tr>
                            <td>{{ $role->name }}</td>
                            <td>{{ $role->cn_name }}</td>
                            <td>{{ $role->created_at }}</td>
                            <td>
                                @if($role->name != 'SuperManager')

                                    @can('edit-role')
                                        <a href="{{ route('role.edit',['id'=>$role->id]) }}" class="btn btn-default btn-sm">编辑</a>
                                    @endcan

                                    @can('delete-role')
                                        <span class="meta pull-right">
                                            <form id="Delete-{{ $role->name }}" action="{{ route('role.destroy',['id'=>$role->id]) }}" method="post">
                                                {{ csrf_field() }}
                                                {{ method_field('DELETE') }}
                                                <button type="button" data-action="Delete-{{ $role->name }}" action="DeleteRole" class="btn btn-default btn-sm pull-left">删除</button>
                                            </form>
                                        </span>
                                    @endcan

                                @endif
                            </td>
                        </tr>
                    @endforeach
                </table>
            @else
                <h5>还没有角色哟，赶快去创建一个吧！</h5>
            @endif
        </div>
        <!-- /.box-body -->
        <div class="box-footer clearfix">
            {{ $roles->links('vendor.pagination.adminlte') }}
        </div>
    </div>
@endsection

@section('Style')
    <link href="https://cdn.bootcss.com/layer/3.1.0/theme/default/layer.css" rel="stylesheet">
@endsection
@section('JavascriptResult')
    <script src="https://cdn.bootcss.com/layer/3.1.0/layer.js"></script>
@endsection

@section('JavascriptScript')
    @can('delete-role')
        $('button[action="DeleteRole"]').on('click',function(){
            var action  = $(this).data('action')
            layer.confirm('确定要删除？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $("#"+action).submit();
            }, function(){
                layer.msg('好的👌', {
                    time: 2000,
                });
            });
        });
    @endcan
@endsection